<?php
require_once 'sisco.php';

/**
 * @package sisco
 * @subpackage controller
 */
class Usuarios_protoweb extends Sisco
{

	public function __construct() 
	{
		parent::__construct();
	}

    protected function createPrepare(&$data)
    {
        
        
        
    
        // Collections of has one relationships
    
        // Collections of has many to many relationships
        $data['grupos'] = new Grupo();
        $data['grupos']->get();
    
    }

    protected function assignCreatePost(&$data)
    {
        if ( array_key_exists('username', $this->input->post()) ) $data['usuario']->username = $this->input->post('username');
        if ( array_key_exists('password', $this->input->post()) ) $data['usuario']->password = $this->input->post('password');
        if ( array_key_exists('nombre', $this->input->post()) ) $data['usuario']->nombre = $this->input->post('nombre');
    
        // has one relationships
        
        // Many to many
        $data['grupos_save'] = $this->input->post('grupos');
    
        return true;
    }

    protected function afterCreateSuccess(&$data)
    {
        
        
        
        
    }

    protected function revertOnCreateError(&$data)
    {
        
        
        
        
    }

    protected function updatePrepare(&$data)
    {
        
        
        
    
        // Collections of has one relationships
        
        // Collections of has many to many relationships
        $data['grupos'] = new Grupo();
        $data['grupos']->get();
    
    }

    protected function assignUpdatePost(&$data)
    {
        if ( array_key_exists('username',$this->input->post()) ) $data['usuario']->username = $this->input->post('username');
        if ( array_key_exists('password',$this->input->post()) ) $data['usuario']->password = $this->input->post('password');
        if ( array_key_exists('nombre',$this->input->post()) ) $data['usuario']->nombre = $this->input->post('nombre');
    
        // has one relationships
    
        // Many to many
        $data['grupos_save'] = $this->input->post('grupos');
        
    
        return true;
    }

    protected function afterUpdateSuccess(&$data)
    {
        
        
        
        
    }

    protected function revertOnUpdateError(&$data)
    {
        
        
        
        
    }

    protected function afterDeleteSuccess(&$data)
    {
        
        
        
        
    }

    protected function readPrepare(&$data)
    {
        
        
        
        
    }

    protected function saveEntity(&$data,$saveHasOne=true,$saveHasMany=true)
    {
        // saving attributes
        if ( ! $data['usuario']->save()) {
            return false;
        }

        // saving one raleted
        if ($saveHasOne) {
            $relationships = array();
            
            if ( ! $data['usuario']->save($relationships)) {
                return false;
            }
        }

        // saving many to many relationships
        if ($saveHasMany) {
                // grupos 
            if (array_key_exists('grupos_save', $data)) {
                $data['usuario']->updateManyToManyWithIdArray('grupo',$data['grupos_save']);
            }

                    }
        return true;
    }

        
        
        
    
} // class Usuarios

/* End of file usuarios_protoweb.php */
/* Location: ./application/controllers/usuarios_protoweb.php */